
/// <reference path="jquery-1.10.2.js" />
var x = {"controller": "/app/controller","searchParams": { "service": "search", "start": 0},"facets": {"cat": {}, "resourcecame": {} },"filters":{}};

// Start Ready
$(document).ready(function () {
    getStores();
    getCrawlers();
});

function getStores() {
    $.getJSON("/app/controller?service=stores&action=list", function (response) {
        $.each(response.stores, function (ix, store) {
            $("#stores").append('<a href="javascript:crawl(\''+store.id+'\')">'+store.name + '</a><br/>');
        });
    });
}

function getCrawlers() {
    $.getJSON("/app/controller?service=crawl&action=list", function (response) {
        $.each(response.crawlers, function (ix, crawler) {
            $("#crawlers").append('<div>');
            for (var property in crawler) {
                $("#crawlers").append(property + " = " + crawler[property]+"; ");
            }
            $("#crawlers").append('</div><br/><br/>');
        });
    });
}

function crawl(id) {
    $.getJSON("/app/controller?service=crawl&action=start&resume=false&store_id="+id, function (response) {
        getCrawlers();
    });

}